<template name="newlogin">
	
		<view class="otherBox">
			
			<view class="imgbox">
				<image src="../static/bglogin.jpg" mode=""></image>
			</view>
			<view class="textbox">
				<text style="margin-right: 5rpx;">找培训</text>
				<text class="iconfont icon-favorfill"></text>
				<text style="margin-left: 5rpx;">拼好课</text>
			</view>
			<view class="quanbox">
				<text>该程序获得以下授权： </text>
			</view>
			<view class="shouquanbox">
				<text>获取您的公开信息（昵称和头像等），以便 于查看优惠信息哦</text>
			</view>
			<view class="btnbox">
				<button class="left">取消</button>
				<button class="right" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">确定授权</button>
			</view>
			
		<!-- 	<view class="otherLogin">
				<button open-type="getUserInfo" @getuserinfo="bindGetUserInfo"><image mode="widthFix" src="../static/wechat.png"></image></button>
			</view> -->
		
			
		</view>
	
</template>

<script>
import COMM from "@/common/common.js";
import {
	mapState,
	mapGetters,
	mapMutation,
	mapActions
} from "vuex";
export default {
	name: 'newlogin', //组件名称
	computed: {
		...mapState({
			initInfo: state => state.sys.initInfo,
			userInfo: state => state.user.userInfo,
			locationCity: state => state.map.locationCity
		})

	},
	data() {
		return {
			pageH: uni.getSystemInfoSync().screenHeight,
			isTelLogin: true,
			tel: '',
			msgCode: '',
			userName: '',
			userPass: '',
			isGetMsg: false,
			sendText: '获取验证码',
			isSendMsg: false,
			thirdList: [],
			cfm: {},
			iosNum: 0,
			isIstWx: false,
			isIstQQ: false,
			userAvat: '',
			sessionKey:'',
			openId:'',
		};
	},
	methods: {
			bindGetUserInfo(e){
				console.log(e)
				
				if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
					uni.showModal({
						title: '授权提醒',
						content: '使用微信第三方登录必须允许微信权限，请再次点击重新授权',
						showCancel: false,
						cancelText: '',
						confirmText: '确认',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				} else { 
					this.$store.dispatch("apiThirdLogin", {
							openId: this.openId,
							nickname: e.detail.userInfo.nickName
						})
						.then(apiRes => {
							
							
							if (apiRes.data.code == 1) {
								
								uni.showToast({
									title: '登录成功',
									icon: 'none'
								});
								setTimeout(() => {
									this.$store.dispatch("timLogin", apiRes.data.data.imid).then(timRes => {})
								}, 1000)
								this.loginJump();
							}
						})
				}
				
			
		},
	
	
		

		loginJump() {
			if (this.cfm.to == "car") { //去购物车
				uni.redirectTo({
					url: "/pagesA/car/car"
				})
			} else if (this.cfm.to == 'addCar') { //添加商品到购物车
				this.$store.dispatch("apiAddGoodToCar", {
					userId: this.userInfo.userId,
					courseId: this.cfm.gid,
					num: 1
				}).then(res => {
					uni.navigateBack({
						delta: 1
					})
					setTimeout(() => {
						uni.showToast({
							title: '添加成功',
							icon: 'success'
						});
					}, 1500)

				})
			} else if (this.cfm.to == "confirmOrder") { //到提交订单页面
				if (this.cfm.isGroup) {
					uni.redirectTo({
						url: "/pagesA/confirmOrder/confirmOrder?isGroup=1&acId=" + this.cfm.acId
					})
				} else if (this.cfm.isLm) {
					uni.redirectTo({
						url: "/pagesA/confirmOrder/confirmOrder?isLm=1&actId="+this.actId
					})
				} else {
					uni.redirectTo({
						url: "/pagesA/confirmOrder/confirmOrder"
					})
				}

			} else {
				// this.toPage('index');
				// uni.navigateBack({
				// 	delta: 1
				// })
			}
		}
	},
	created() {
		this.$store.dispatch("loginByWexin").then(res=>{
			this.sessionKey=res.data.data.session_key;
			this.openId=res.data.data.unionid?res.data.data.unionid:res.data.data.openid
		})
	},
	onLoad(cfm) {
		this.cfm = cfm;
		this.actId = cfm.actId;
		// this.$store.dispatch("loginByWexin").then(res=>{
		// 	this.sessionKey=res.data.data.session_key;
		// 	this.openId=res.data.data.unionid?res.data.data.unionid:res.data.data.openid
		// })
	}
}
</script>

<style lang="less">

.otherBox {
	position: relative;
	width: 512rpx;
	height: 665rpx;
	background-color: #fff;
	border-radius: 20rpx;
	overflow: hidden;

		.imgbox{
			width: 100%;
			image{
				width: 100%;
				height: 245rpx;
			}
		}
		.textbox{
			padding: 0 20rpx;
			width: 100%;
			text-align: center;
			font-size: 32rpx;
			font-weight: bold;
			color: #4e4e4e;
			margin: 20rpx 0;
		}
		.quanbox{
			color: #4e4e4e;
			font-size: 30rpx;
			font-weight: bold;
			padding: 0 20rpx;
		}
		.shouquanbox{
			padding: 0 20rpx;
			width: 100%;
			// text-align: center;
			color: #c9c9c9;
			font-size: 26rpx;
			margin: 25rpx 0;
		}
		.btnbox{
			width: 100%;
			position: absolute;
			bottom:40rpx;
			left: 0;
			display: flex;
			justify-content: center;
			button{
				height: 80rpx;
				width: 215rpx;
				border-radius: 40rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 30rpx;
				color:#4e4e4e;
				font-weight: bold;
			}
			.left{
				background-color: #fff;
				border: 1px solid #c9c9c9;
				
			}
			.right{
				background-color: #fce024;
			}
			
		}
			
}
</style>
